﻿//蓝色 00a2ff  红色 e1504a
//获得焦点**************************************************************************************
function ThisOnfocus(ObjID)
{
    $(".tc-msg").hide(); //隐藏顶部提示
    var objText = $("#" + ObjID).val();
    //手机号码
    if (ObjID == "reg_phone")
    {
        if ($("#reg_phone").attr("vdata") == "2")
        {
            if (objText == "" || objText == null)
            {
                $("#reg_phone").css("border", "1px solid #e1504a");
                $("#reg_phone_mes").css("color", "#e1504a");
                $("#reg_phone_mes").html("请输入手机号码");
                $("#reg_phone_mes").animate({ lineHeight: "45px"  }, 300);
                return false;
            }
        }
        else
        {
            $("#reg_phone").attr("vdata", "0");
            if (objText == "" || objText == null)
            {
                $("#reg_phone").css("border", "1px solid #00a2ff");
                $("#reg_phone_mes").hide();
                return false;
            }
        }
    }
    if (ObjID == "reg_email")
    {
        if ($("#reg_email").attr("vdata") == "2")
        {
            if (objText == "" || objText == null)
            {
                $("#reg_email").css("border", "1px solid #e1504a");
                $("#reg_email_mes").css("color", "#e1504a");
                $("#reg_email_mes").html("请输入手机号码");
                $("#reg_email_mes").animate({ lineHeight: "45px"  }, 300);
                return false;
            }
        }
        else
        {
            $("#reg_email").attr("vdata", "0");
            if (objText == "" || objText == null)
            {
                $("#reg_email").css("border", "1px solid #00a2ff");
                $("#reg_email_mes").hide();
                return false;
            }
        }
    }
    if (ObjID == "reg_username")
    {
        if ($("#reg_username").attr("vdata") == "2")
        {
            if (objText == "" || objText == null)
            {
                $("#reg_username").css("border", "1px solid #e1504a");
                $("#reg_username_mes").css("color", "#e1504a");
                $("#reg_username_mes").html("请输入手机号码");
                $("#reg_username_mes").animate({ lineHeight: "45px"  }, 300);
                return false;
            }
        }
        else
        {
            $("#reg_username").attr("vdata", "0");
            if (objText == "" || objText == null)
            {
                $("#reg_username").css("border", "1px solid #00a2ff");
                $("#reg_username_mes").hide();
                return false;
            }
        }
    }
    //密码
    else if (ObjID == "reg_password")
    {
        if ($("#reg_password").attr("vdata") == "2")
        {
            if (objText == "" || objText == null)
            {
                $("#reg_password").css("border", "1px solid #e1504a");
                $("#reg_password_mes").css("color", "#e1504a");
                $("#reg_password_mes").html("请输入密码");
                $("#reg_password_mes").animate({ lineHeight: "45px" }, 300);
                return false;
            }
        }
        else
        {
            $("#reg_password").attr("vdata", "0");
            if (objText == "" || objText == null)
            {
                $("#reg_password").css("border", "1px solid #00a2ff");
                $("#reg_password_mes").css("color", "#aaa");
                $("#reg_password_mes").html("密码6-20个字符");
                $("#reg_password_mes").animate({  lineHeight: "45px"  }, 300);
                return false;
            }
        }
    }
    //确认密码
    else if (ObjID == "reg_pswqueren")
    {
        if ($("#reg_pswqueren").attr("vdata") == "2")
        {
            if (objText == "" || objText == null)
            {
                $("#reg_pswqueren").css("border", "1px solid #e1504a");
                $("#reg_pswqueren_mes").css("color", "#e1504a");
                $("#reg_pswqueren_mes").html("请输入确认密码");
                $("#reg_pswqueren_mes").animate({  lineHeight: "45px"  }, 300);
                return false;
            }
        }
        else
        {
            $("#reg_pswqueren").attr("vdata", "0");
            if (objText == "" || objText == null)
            {
                $("#reg_pswqueren").css("border", "1px solid #00a2ff");
                $("#reg_pswqueren_mes").hide();
                return false;
            }
        }
    }
    //验证码
    else if (ObjID == "reg_yzm")
    {
        if ($("#reg_yzm").attr("vdata") == "2")
        {
            if (objText == "" || objText == null)
            {
                $("#reg_yzm").css("border", "1px solid #e1504a");
                $("#reg_yzm_mes").css("color", "#e1504a");
                $("#reg_yzm_mes").html("请输入手机短信验证码");
                $("#reg_yzm_mes").animate({  lineHeight: "45px"  }, 300);
                return false;
            }
        }
        else
        {
            $("#reg_yzm").attr("vdata", "0");
            if (objText == "" || objText == null)
            {
                $("#reg_yzm").css("border", "1px solid #00a2ff");
                $("#reg_yzm_mes").animate({ height: "0px" }, 100);
                return false;
            }
        }
    }
}
//失去焦点**************************************************************************************
function ThisOnblur(ObjID)
{
    $(".tc-msg").hide(); //隐藏顶部提示
    var objText = $("#" + ObjID).val();
    var isMobile = /^1[3|4|5|7|8]\d{9}$/; //手机号码验证规则
    //手机======================================
    if (ObjID == "reg_phone")
    {
        checkmobile();
    }
    if (ObjID == "reg_email")
    {
        checkemail();
    }
    if (ObjID == "reg_username")
    {
        checkusername();
    }
    //密码======================================
    else if (ObjID == "reg_password")
    {
        $("#reg_password").attr("vdata", "0");
        if (objText == "" || objText == null)
        {
            $("#reg_password").css("border", "1px solid #ddd");
            $("#reg_password_mes").hide();
            return false;
        }
        else if (objText.length < 6 || objText.length > 20)
        {
            $("#reg_password").css("border", "1px solid #e1504a");
            $("#reg_password_mes").css("color", "#e1504a");
            $("#reg_password_mes").html("密码应该为6-20个字符");
            $("#reg_password_mes").animate({  lineHeight: "45px"  }, 300);
            return false;
        }
        else if (!checkRule())
        {
            $("#reg_password").css("border", "1px solid #e1504a");
            $("#reg_password_mes").css("color", "#e1504a");
            $("#reg_password_mes").html("密码至少包含字母、数字、符号中两种");
            $("#reg_password_mes").animate({  lineHeight: "45px"  }, 300);
            return false;
        }
        else
        {
            $("#reg_password_mes").hide();
            if ($("#reg_pswqueren").val() == "" || $("#reg_pswqueren").val() == null)
            {
                $("#reg_password").css("border", "1px solid #ddd");
                $("#reg_password").attr("vdata", "1");
                $("#reg_password_mes").hide();
            }
            else
            {
                $("#reg_password").css("border", "1px solid #ddd");
                $("#reg_password").attr("vdata", "1");
                $("#reg_password_mes").hide();
                $("#reg_pswqueren").attr("vdata", "1");
                $("#reg_pswqueren").css("border", "1px solid #ddd");
                $("#reg_pswqueren_mes").animate({ height: "0px" }, 100);

                //验证密码 回头又修改
                if ($("#reg_password").val() != $("#reg_pswqueren").val())
                {
                    $("#reg_password_mes").show();
                    $("#reg_pswqueren").attr("vdata", "0");
                    $("#reg_pswqueren_mes").animate({  lineHeight: "45px"  }, 300);
                    $("#reg_pswqueren").css("border", "1px solid #e1504a");
                    $("#reg_pswqueren_mes").css("color", "#e1504a");
                    $("#reg_pswqueren_mes").html("两次输入的密码不一致，请重新输入");
                    $("#reg_pswqueren").focus();
                    return false;
                }
            }
        }
    }
    //确认密码======================================
    else if (ObjID == "reg_pswqueren")
    {
        $("#reg_pswqueren").attr("vdata", "0");
        if ($("#reg_password").val() != $("#reg_pswqueren").val())
        {
			if($("#reg_pswqueren_mes").is(':hidden')){
               $("#reg_pswqueren_mes").show();
			}
            $("#reg_pswqueren_mes").animate({ lineHeight: "45px" }, 300);
            $("#reg_pswqueren").css("border", "1px solid #e1504a");
            $("#reg_pswqueren_mes").css("color", "#e1504a");
            $("#reg_pswqueren_mes").html("两次输入的密码不一致，请重新输入");
            return false;
        }
        else
        {
            $("#reg_pswqueren").css("border", "1px solid #ddd");
            $("#reg_pswqueren").attr("vdata", "1");
            $("#reg_pswqueren_mes").hide();
        }
    }
    //手机验证码======================================
    else if (ObjID == "reg_yzm")
    {
        $("#reg_yzm").attr("vdata", "0");
        if (objText == "" || objText == null)
        {
            $("#reg_yzm").css("border", "1px solid #ddd");
            $("#reg_yzm_mes").animate({ height: "0px" }, 100);
            return false;
        }
        else
        {
            var myReg = /^[0-9]{6,6}$/;
            if (!myReg.test(objText))
            {
                $("#reg_yzm").css("border", "1px solid #e1504a");
                $("#reg_yzm_mes").css("color", "#e1504a");
                $("#reg_yzm_mes").html("请正确输入6位数字验证码");
                $("#reg_yzm_mes").animate({ lineHeight: "45px" }, 300);
                return false;
            }
            else
            {
                $("#reg_yzm").css("border", "1px solid #ddd");
                $("#reg_yzm").attr("vdata", "1");
                $("#reg_yzm_mes").animate({ height: "0px" }, 100);
            }
        }
    }
}
//内容改变时**************************************************************************************
function ThisOnkeyup(ObjID)
{
    $(".tc-msg").hide(); //隐藏顶部提示
    var objText = $("#" + ObjID).val();
    //手机号码===================
    if (ObjID == "reg_phone")
    {
        $("#reg_phone").css("border", "1px solid #00a2ff"); //蓝色
        $("#reg_phone_mes").hide();
        return false;
    }else if (ObjID == "reg_email")
    {
        $("#reg_email").css("border", "1px solid #00a2ff"); //蓝色
        $("#reg_email_mes").hide();
        return false;
    }else if (ObjID == "reg_username")
    {
        $("#reg_username").css("border", "1px solid #00a2ff"); //蓝色
        $("#reg_username_mes").hide();
        return false;
    }
    //确认密码===================
    else if (ObjID == "reg_password")
    {
        $("#reg_password").css("border", "1px solid #00a2ff"); //蓝色
        $("#reg_password_mes").css("color", "#aaa");

        if ($("#reg_password").val() == $("#reg_pswqueren").val() && $("#reg_pswqueren").val() != "")
        {
            $("#reg_pswqueren").css("border", "1px solid #ddd");
            $("#reg_pswqueren").attr("vdata", "1");
            $("#reg_pswqueren_mes").animate({ height: "0px" }, 100);
        }
        return false;
    }
    //确认密码===================
    else if (ObjID == "reg_pswqueren")
    {
        $("#reg_pswqueren").css("border", "1px solid #00a2ff"); //蓝色
        $("#reg_pswqueren_mes").hide();
        return false;
    }
    //验证码===================
    else if (ObjID == "reg_yzm")
    {
        $("#reg_yzm").css("border", "1px solid #00a2ff"); //蓝色
        $("#reg_yzm_mes").animate({ height: "0px" }, 100);
        return false;
    }
}

//密码规则**************************************************************************************
function checkRule()
{
    var len = 1;
    var Aq = 0;
    var objpsw = $("#reg_password").val();
    len = objpsw.length;
    if (/[a-zA-Z]/.test(objpsw))
    {
        Aq = Aq + 1;
    }
    if (/[0-9]/.test(objpsw))
    {
        Aq = Aq + 1;
    }
    if (/[!,@,#,$,%,^,&,*,?,_,~,-,(,)]/.test(objpsw))
    {
        Aq = Aq + 1;
    }
    if (Aq >= 1)
    {
        return true;
    }
    else
    {
        return false;
    }
}

function checkmobile(){
	  var objText =$("#reg_phone").val();
      var isMobile = /^1[3|4|5|6|7|8|9]\d{9}$/; //手机号码验证规则
	   if (objText == "" || objText == null)
        {
            $("#reg_phone").css("border", "1px solid #e1504a");
            mui.toast("手机号码为空",{type:'div'}); 
            return false;
        }
        else if (!isMobile.test(objText))
        {
            $("#reg_phone").css("border", "1px solid #e1504a");
            mui.toast("手机号码格式有误，请修改",{type:'div'}); 
            return false;
        }
        else
        {
            $.ajax({
                data: {
                    mobile: $("#reg_phone").val()
                },
                type: "post",
                dataType: "json",
                url: "/index.php?a=checkphone&c=member&m=member",
                success: function (data)
                {
                    console.log(data);
                    if(data.code!= "100")
                    {
                        mui.toast(data.msg,{type:'div'}); 
                    }else{
                        $("#reg_phone").css("border", "1px solid #ddd");
                        $("#reg_phone_mes").hide();
                        $("#reg_phone").attr("vdata", "1");
                    }
                }
            })
        }
}


function checkemail(){
    var objText =$("#reg_email").val();
    var isEmail = /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/;
     if (objText == "" || objText == null)
      {
          $("#reg_email").css("border", "1px solid #e1504a");
          mui.toast("邮箱号码为空",{type:'div'}); 
          return false;
      }
      else if (!isEmail.test(objText))
      {
          $("#reg_email").css("border", "1px solid #e1504a");
          mui.toast("邮箱号码格式有误，请修改",{type:'div'}); 
          return false;
      }
      else
      {
          $.ajax({
              data: {
                  email: $("#reg_email").val()
              },
              type: "post",
              dataType: "json",
              url: "/index.php?a=checkemail&c=member&m=member",
              success: function (data)
              {
                  console.log(data);
                  if(data.code!= "100")
                  {
                      mui.toast(data.msg,{type:'div'}); 
                  }else{
                      $("#reg_email").css("border", "1px solid #ddd");
                      $("#reg_email_mes").hide();
                      $("#reg_email").attr("vdata", "1");
                  }
              }
          })
      }
}


function checkusername(){
    var objText =$("#reg_username").val();
          $.ajax({
              data: {
                  username: $("#reg_username").val()
              },
              type: "post",
              dataType: "json",
              url: "/index.php?a=checkUname&c=member&m=member",
              success: function (data)
              {
                  if(data.code!= "100")
                  {
                      mui.toast(data.msg,{type:'div'}); 
                  }else{
                      $("#reg_username").css("border", "1px solid #ddd");
                      $("#reg_username_mes").hide();
                      $("#reg_username").attr("vdata", "1");
                  }
              }
          })
}



//获取手机验证码**************************************************************************************
function GetCode(mobile,smstype,posturl,buttonid)
{
    var buttonid = arguments[3] ? arguments[3] : "ButtonCode";
    if(mobile == "" || mobile == null){
        mui.toast("手机号码错误",{type:'div'}); 
    }
	 if(checkmobile()!=false){
	    $("#"+buttonid).html("正在获取...").attr("disabled", "disabled").css("cursor", "not-allowed").css("background", "#3598dc");
        $.ajax({
            data: {
                mobile:mobile,
                smstype: smstype
            },
            type: "post",
            dataType: "json",
            url:posturl,
            success: function (data)
              {
                   console.log(data.code);
                    if(data.code==100){
                        seconds = 60; //60秒后重新获取
                        objTimer = window.setInterval(redirection, 1000);
                    }
                    else if(data.code!=100){
                        mui.toast(data.msg,{type:'div'});
                        $("#"+buttonid).html("重新发送验证码").removeAttr("disabled").css("cursor", "pointer").css("background", "#3598dc").css("color", "#fff");
                    }else{
                        mui.toast(data.msg,{type:'div'}); 
                        $("#"+buttonid).html("重新发送验证码").removeAttr("disabled").css("cursor", "pointer").css("background", "#3598dc").css("color", "#fff");
                    }
              }
           })		
	}
}

//获取邮箱验证码**************************************************************************************
function GetEmailCode(email,smstype,posturl,buttonid)
{
    var buttonid = arguments[3] ? arguments[3] : "ButtonCode";
    if(email == "" || email == null){
         mui.toast("用户Email输入错误",{type:'div'}); 
    }
	 if(checkemail(email)!=false){  
	    $("#"+buttonid).html("正在获取...").attr("disabled", "disabled").css("cursor", "not-allowed").css("background", "#3598dc");
        $.ajax({
            data: {
                email:email,
                emailtype: smstype
             },
            type: "post",
            dataType: "json",
            url:posturl,
            success: function (data)
              {
                    console.log(data.code);
                    if(data.code==100){
                        seconds = 60; //60秒后重新获取
                        objTimer = window.setInterval(redirection, 1000);
                    }else if(data.code!=100){ 
                        mui.toast(data.msg,{type:'div'});
                        $("#"+buttonid).html("重新发送验证码").removeAttr("disabled").css("cursor", "pointer").css("background", "#3598dc").css("color", "#fff");
                    }else{
                        mui.toast(data.msg,{type:'div'}); 
                        $("#"+buttonid).html("重新发送验证码").removeAttr("disabled").css("cursor", "pointer").css("background", "#3598dc").css("color", "#fff");
                    }
              }
           })		
	}
}


//计时器**************************************************************************************
function redirection()
{
    seconds--;
    buttonid="ButtonCode"
    $("#"+buttonid).html(seconds + "秒后重新获取");
    $("#"+buttonid).css("color", "#fff");
    if (seconds == 0)
    {
        window.clearInterval(objTimer);
        $("#"+buttonid).html("重新发送验证码").removeAttr("disabled").css("cursor", "pointer").css("background", "#3598dc").css("color", "#fff");
    }
}
//开始注册**************************************************************************************
function GoRegister()
{
    var regtype=$("#regtype").val();
    if(regtype==1){
        if ($("#reg_phone").attr("vdata") != "1")
        {
            $("#reg_phone").attr("vdata", "2");
            $("#reg_phone").focus();
            return false;
        }
    }
    if(regtype==2){
        if ($("#reg_email").attr("vdata") != "1")
        {
            $("#reg_email").attr("vdata", "2");
            $("#reg_email").focus();
            return false;
        }
    }
    if(regtype!=3){
        if ($("#reg_yzm").attr("vdata") != "1")
        {
            $("#reg_yzm").attr("vdata", "2");
            $("#reg_yzm").focus();
            return false;
        }
    }

    if ($("#reg_password").attr("vdata") != "1")
    {
        $("#reg_password").attr("vdata", "2");
        $("#reg_password").focus();
        return false;
    }
    else if ($("#reg_pswqueren").attr("vdata") != "1")
    {
        $("#reg_pswqueren").attr("vdata", "2");
        $("#reg_pswqueren").focus();
        return false;
    }
    else
    {
        $("#btnRegister").html("注册中...").attr("disabled", "disabled").css({ "cursor": "not-allowed", "background": "url(/skin_mobile/images/loading_a.gif) 145px 6px #bbb no-repeat" });
        //开始注册
        $.ajax({ 
            data: {
                username: $("#reg_username").val(),
                mobile: $("#reg_phone").val(),
                email: $("#reg_email").val(),
                pwd: $("#reg_password").val(),
                code: $("#reg_yzm").val(),
                regtype: $("#regtype").val(),
				tid:  $("#tid").val(),
				token: $("#safecode").val()
            },
            type: "post",
            dataType: "json",
            url: "/index.php?a=register_check_ajax&c=member&m=member",
            success: function (data)
            {
                if(data.code==100){
                    window.location.href="/index.php?m=member&c=member&a=index";
                }
                else if(data.code!=100){
                    mui.toast(data.msg,{type:'div'});
                    $("#btnRegister").html("注册").removeAttr("disabled").css({ "cursor": "pointer", "background": "#3598dc" });
                }else{
                    mui.toast(data.msg,{type:'div'}); 
                    $("#btnRegister").html("注册").removeAttr("disabled").css({ "cursor": "pointer", "background": "#3598dc" });
                }             
            }
        })
    }
}